package com.sky.controller.admin;


import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/admin/setmeal")
@Api(tags = "套餐管理")
@RestController
public class SetmealComtroller {

    @Autowired
    private SetmealService setmealService;

    @PutMapping
    @ApiOperation("修改套餐")
    public Result upda(@RequestBody SetmealDTO setmealDTO) {
        setmealService.upda(setmealDTO);
        return Result.success();
    }

    @ApiOperation("根据id查套餐")
    @GetMapping
    public Result getById(Long id) {
        SetmealVO setmealVO = setmealService.getById(id);
        return Result.success(setmealVO);
    }

    /**
     * 新增套餐
     *
     * @param dto
     * @return
     */
    @ApiOperation("新增套餐")
    @PostMapping
    public Result add(@RequestBody SetmealDTO dto) {
        log.info("套餐请求参数{}", dto);
        setmealService.add(dto);
        return Result.success();
    }

    /**
     * 起售停售套餐
     *
     * @param status
     * @return
     */
    @ApiOperation("起售停售套餐")
    @PostMapping("/status/{status}")    //                       请求路径 参数值
    public Result updateStatus(@PathVariable Integer status, @RequestParam Integer id) {

        setmealService.updateStatus(status, id);
        return Result.success();
    }


    /**
     * 分页查询
     *
     * @param page
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分页查询")
    private Result get(SetmealPageQueryDTO page) {

        //返回套餐集合
        PageResult pageResult = setmealService.get(page);

        return Result.success(pageResult);
    }


    @DeleteMapping()
    @ApiOperation("批量删除套餐")
    private Result deleteById(@RequestParam("ids") List<Long> ids) {
        log.info("接到前端请求{}", ids);
        setmealService.deleteById(ids);
        return Result.success();
    }

}
